// This script allow you to return 'fake' responses for any requests you like.
// By setting the logic in proxyRequest(), the request will not be sent to the server.
// By setting the logic in proxyResponse(), the request will be sent to the server.

function proxyRequest(msg) {
  // Change this test to match whatever requests you want to fake
  if (
    msg
      .getRequestHeader()
      .getURI()
      .toString()
      .equals("http://localhost:8080/bodgeit/about.jsp")
  ) {
    print(
      "Faking response for url " + msg.getRequestHeader().getURI().toString()
    );

    msg.setResponseBody(
      '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">\n' +
        "<html><head></head><body><h1>Hack</h1>\n" +
        "This is content generated by the script\n" +
        "</body></html>"
    );
    msg.setResponseHeader(
      "HTTP/1.1 200 OK\r\n" + "Content-Type: text/html; charset=UTF-8"
    );
    msg.getResponseHeader().setContentLength(msg.getResponseBody().length());
  }
  return true;
}

function proxyResponse(msg) {
  // Dont typically need to do anything here
  return true;
}
